package com.store.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Component
@RestController
@RequestMapping("config")
@RefreshScope
public class ConfigController {

    @Value("${user.id:2020}")
    private String id;
    @Value("${user.age:120}")
    private String age;
    @Value("${user.name:fcl}")
    private String name;

    @GetMapping("/get")
    @Operation(summary = "查询nacos配置")
    public String get() {
        return "id是: " + id + " 年龄是: " + age + "名字叫: " + name;
    }

    @GetMapping("/SentinelFeign")
    @SentinelResource(value = "SentinelFeign")
    @Operation(summary = "测试SentinelFeign")
    public Integer FeignTriggerSentinel() throws InterruptedException{
        int a = Integer.valueOf(id);
        int b = Integer.valueOf(age);
        int c = a/b;
        return c;
    }

}
